/**--------------------------------------------*/
/** JS:  cmi_role_list.js（角色管理--列表）          */
/**--------------------------------------------*/
var tipc = 'ADMIN_POWER_CMI_ROLE';
var url = "impl_search/commonsPaginSearch.ajax";
var eidtJump = "adminback/roleEditPage.form";

$(function(){
	try {
		loadMemberPanel();
	} catch (e) {
		showJsException(e,"数据加载失败!");
	}	
});

var loadMemberPanel = function() {
	var columns = [ {field : 'roleName',title : '角色名称',width : 150,align : 'center',formatter:function(value){return MyUtils.valueAlign(value,"left");}},
					{field : 'roleDesc',title : '角色描述',width : 250,align : 'center',formatter:function(value){return MyUtils.valueAlign(value,"left");}}
				];
	var pam = {rows:200,page:1,qr:"[]",st:tipc,sco:'',dc:Dmlx.sort.desc};
	MyUtils.createPaginPanelWithQueryparams('dataPanel',null,Dmlx._hFrozenColumns,columns,toolbars,dbclick, panel,null);
	$('#dataPanel').datagrid({
		url:url,
		queryParams:pam,
		pagination:false,
		fitColumns:true
	});
	
};

var dbclick = function(index,row){
	$('#dataPanel').datagrid("clearSelections");
	$('#dataPanel').datagrid("selectRow",index);
	modify();
};

var add = function(){
	var p = eidtJump + "?qr=[]&menuId="+menuId+"&dt=";
	location.replace(p);
};

var modify = function() {
	var rows = $('#dataPanel').datagrid("getSelections");
	if(rows.length != 1) {
		MyUtils.waring(_single_select);
		return;
	}
	var record = MyUtils.toJsonStr(rows[0]);
	var p = eidtJump + "?qr=[]&menuId="+menuId+"&dt="+record;
	location.replace(p);
};

var remove = function() {
	var rows = $('#dataPanel').datagrid("getSelections");
	if(rows.length == 0) {
		MyUtils.waring(_empty_select);
		return;
	}
	try {
		if (rows) {
			$.messager.confirm(_msg_sys,MyUtils.valueAlign(_remove_confirm,"left"), function(r) {
				if (r) {
					var ids = new Array();
					var names = new Array();
					for(var i = 0; i < rows.length; i++) {
						ids.push(rows[i].uuid);
						names.push(rows[i].roleName);
					}
					var data = {data:ids.toString(),st:tipc,msg:names.toString()};
					MyUtils.openMask(_msg_process,$('#t2'));
					MyUtils.sendPost("impl_remove/backRemove.adm",data,function(msg){
						try{
							MyUtils.hiddenMask($('#t2'));
							var res = MyUtils.toJsonObject(msg);
							if(res.error == '0') {
								MyUtils.info(res.msg);
								$('#dataPanel').datagrid("reload");
								$('#dataPanel').datagrid("clearSelections");
							} else {
								MyUtils.error(res.msg);
							}
						} catch (e) {
							MyUtils.hiddenMask($('#t2'));
							MyUtils.error(_msg_fail);
						}
					});
				}
			});
		}
	} catch (e) {
		MyUtils.hiddenMask('#t2');
		showJsException(e,_msg_fail);
	}
};